package com.android.hedgehog;

import android.graphics.Color;
import android.util.Log;

import com.android.hedgehog.framework.Game;
import com.android.hedgehog.framework.Graphics;
import com.android.hedgehog.framework.Input;
import com.android.hedgehog.framework.Screen;

public class RisingConnectionScreen extends Screen {
	public enum GameState {
		Ready, Phase1, Phase2, Phase3
	}
	Graphics g;
	public FingerTrace ft;
	public RisingNumbers rns;
	int hitMiss;
	GameState state;
	Input input;
	float bufferTime,bufferTime2;

	public RisingConnectionScreen(Game game) {
		super(game);
		g = game.getGraphics();
		rns = new RisingNumbers((int) ((Math.random() * 10) + 1));
		ft = new FingerTrace(game.getInput(), game.getGraphics(),rns.totalBoxes,this);
		
		state = GameState.Phase1;
	}

	@Override
	public void update(float deltaTime) {
		
		

		if (state == GameState.Phase1) {
			ft.traceLine();
			for (int i = rns.listOrder; i < rns.choices.length; i++) {
				if (ft.ifHit(rns.choices[i].xPosition,
						rns.choices[i].yPosition, 40, 40)) {
					if (i == rns.listOrder) {
						rns.listOrder++;
						state = GameState.Phase2;
					} else
						state = GameState.Phase3;
					bufferTime=deltaTime;
					break;
				}// ifHit
			}
		}// Phase1

		if (state == GameState.Phase2) {
			if (rns.choices[rns.listOrder-1].xPosition < ft.x
					&& rns.choices[rns.listOrder].xPosition + 40 > ft.x
					&& rns.choices[rns.listOrder].yPosition < ft.y
					&& rns.choices[rns.listOrder].yPosition + 40 > ft.y) {
				
				ft.traceLine();
				state = GameState.Phase1;
			}
		}

	}

	@Override
	public void present(float deltaTime) {
		g.drawPixmap(Assets.blackbackground, 0, 0);

		for (int i = 0; i < rns.choices.length; i++) {
			g.drawRect2(rns.choices[i].xPosition, rns.choices[i].yPosition, 40,
					40, Color.GREEN);
			g.drawText(rns.choices[i].string, rns.choices[i].xPosition + 20,
					rns.choices[i].yPosition + 28, 20, Color.BLUE);
		}
			for (int i = 0; i < rns.listOrder; i++) {
				g.drawRect(rns.choices[i].xPosition, rns.choices[i].yPosition,
						40, 40, Color.GREEN);
				g.drawText(rns.choices[i].string,
						rns.choices[i].xPosition + 20,
						rns.choices[i].yPosition + 28, 20, Color.BLACK);
			}

		ft.drawLine(0, 31, 320, 449, Color.GREEN);

	}
	@Override
	public void pause() {
		// TODO Auto-generated method stub

	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub

	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub

	}

}
